export const isFunction = (target) => {
  return typeof target === 'function'
}

/**
 * 判断对象、数组、字符串等是否为空
 * @param {*} value 需要判断的值
 * @returns {boolean} 如果为空则返回 true，否则返回 false
 */
export function isAllEmpty(value) {
  // null 或 undefined
  if (value === null || value === undefined) {
    return true;
  }

  // 字符串类型
  if (typeof value === 'string') {
    return value.trim() === '';
  }

  // 数组类型
  if (Array.isArray(value)) {
    return value.length === 0;
  }

  // 对象类型
  if (typeof value === 'object' && value !== null) {
    return Object.keys(value).length === 0;
  }

  // 其他情况不为空
  return false;
}

// 是否为url超链接
export function isUrl(value) {
  return /^https?:\/\//.test(value);
}


export const isBoolean = (target) => {
  return typeof target === 'boolean'
}

export const isString = (target) => {
  return typeof target === 'string'
}

export const isObject = (target) => {
  return Object.prototype.toString.call(target) === '[object Object]'
}

export const isPromise = (target) => {
  return target instanceof Promise
}

export const isArray = (target) => {
  return Array.isArray(target)
}

export const isNumber = (target) => {
  return typeof target === 'number'
}

export const isArrayOfString = (target) => {
  return isArray(target) && target.every(item => (typeof item === 'string'))
}

export const isAsyncFunction = (fn) => {
  return fn.constructor.name === 'AsyncFunction';
}

